﻿using LibraryMangementSystem.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryMangementSystem.BookQuery
{
    public partial class BookQueryByClass : Form
    {
        public BookQueryByClass()
        {
            InitializeComponent();
        }
        LibraryEntities1 dbContext = new LibraryEntities1();
        private void buttonQueryByClass_Click(object sender, EventArgs e)
        {
            var ClassId = ((ComboBoxItem)comboBoxQueryByClass.SelectedItem).Value.ToString();
            List<BookInfo> list = dbContext.BookInfo.Where(B => B.ClassID == ClassId).ToList();
            dataGridViewByClass.Rows.Clear();
            foreach (BookInfo book in list)
            {
                dataGridViewByClass.Rows.Add(book.BookID.Trim(), book.ISBN.Trim(), book.Title.Trim(), book.Publish.Trim(),
                    book.Author.Trim(), book.Words, book.Publisherlnfo != null ? book.Publisherlnfo.Publisher.Trim() : null, book.Number, book.Price,
                    book.Keyword.Trim(), book.Abstract.Trim());
            }

        }
        private void dataViewByLoad(object sender,EventArgs e)
        {
            foreach (var item in dbContext.BookClass)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Text = item.Classname.Trim();
                cbi.Value = item.ClassID;
                comboBoxQueryByClass.Items.Add(cbi);
            }
            comboBoxQueryByClass.SelectedIndex = 0;
        }
    }
}
